
import java.util.Random;
public class instackfg {

        private Integer[] elements;
        private int size=0;
        public static final int DEFAULT_CAPACITY=10;

        public instackfg(int size) { elements= new Integer[size];}

        public instackfg(){ this(DEFAULT_CAPACITY); }
        public void push(Integer value){
            if (size>=elements.length){
                Integer[] temp = new Integer[elements.length*2];
                System.arraycopy(elements,0,temp,0,elements.length);
                elements = temp;
            }
            elements[size++] = value;
        }

        public Integer pop(){
            return elements[--size];
        }
        public Integer peek(){
            return elements[size-1];
        }
        public boolean empty(){
            return size==0;
        }
        public int size(){
            return size;
        }


    public static void main(String[] args) {



            instackfg stack=new instackfg();
            Random rand = new Random();
            for (int i=0;i<=10;i++){
                Integer n=Integer.valueOf(rand.nextInt(100));
                System.out.print(n+ " ");
                stack.push(n);
            }
            System.out.println();
            System.out.println("栈到大小："+stack.size);
            while(!stack.empty()){
                System.out.print(stack.pop() + " ");
            }
        }


}
